#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,l,V;
int p[100005];

struct car{
    int d,v,a;
}c[100005];

int ans;

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
bool flag=true;
    cin>>T;
    for(int t=1;t<=T;t++){
        flag=true;
        memset(p,0,sizeof(p));
        memset(c,0,sizeof(c));
        ans=0;
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++){
                cin>>c[i].d>>c[i].v>>c[i].a;
                if(c[i].a!=0){
                    flag=false;
                }
        }

        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        //sort(p+1,p+n+1);
        for(int i=1;i<=n;i++){
            if(c[i].d<=p[m]){
                    if(c[i].v>V){
                    ans++;
                }
        }
        }

        if(flag){
                if(ans==0){
                    m+=1;
                }
                //cout<<n<<" "<<V<<" "<<l<<" ";
            cout<<ans<<" "<<m-1<<endl;
            continue;
        }

    }


    return 0;
}
